from django.db import models
from pygments.lexers import get_all_lexers
from pygments.styles import get_all_styles
from model_utils.models import TimeStampedModel

LEXERS = [item for item in get_all_lexers() if item[1]]
LANGUAGE_CHOICES = sorted([(item[1][0], item[0]) for item in LEXERS])
STYLE_CHOICES = sorted((item, item) for item in get_all_styles())


class Snippet(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=100, blank=True, default='')
    code = models.TextField()
    linenos = models.BooleanField(default=False)
    language = models.CharField(choices=LANGUAGE_CHOICES, default='python', max_length=100)
    style = models.CharField(choices=STYLE_CHOICES, default='friendly', max_length=100)

    class Meta:
        ordering = ('created',)

class UserProfile(TimeStampedModel):
    user = models.OneToOneField(User, unique=True, db_index=True,
		related_name='profile')
    name = models.CharField(blank=True, max_length=255, db_index=True)
    phone = models.CharField(default='', blank=True, max_length=64)
    nickname = models.CharField(blank=True, null=True, max_length=255,
                db_index=True)
    avatar = models.URLField(blank=True, max_length=255, default='')
    is_cms_user = models.BooleanField(default=False, db_index=True)
    is_cms_active = models.BooleanField(default=False, db_index=True)

    class Meta:  # pylint: disable=missing-docstring
        db_table = "auth_userprofile"

    def __unicode__(self):
        return self.name

